﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ent;
namespace DAL
{
    public class DeThiDAL:clsKetNoi
    {
        dataDataContext dt;
        public List<DeThiTbl> LayDanhSachDeThi_MaMonHoc(string MaMonHoc, string mssv)
        {
            dt = GetKetnoi();
            IEnumerable<DETHI> q = (from i in dt.MONHOCs
                                    join u in dt.CHUONGs on i.MAMONHOC equals u.MAMONHOC
                                    join j in dt.CAUHOIs on u.MACHUONG equals j.MACHUONG
                                    join z in dt.CHITIETDETHIs on j.MACAUHOI equals z.MACAUHOI
                                    join x in dt.DETHIs on z.MADETHI equals x.MADETHI
                                    join y in dt.DIEMs on x.MADETHI equals y.MADETHI
                                    where y.MSSV == mssv && u.MAMONHOC == MaMonHoc
                                    select x).Distinct();
            List<DeThiTbl> dsmh = new List<DeThiTbl>();
            foreach (DETHI item in q)
            {
                DeThiTbl mh = new DeThiTbl();
                mh.MADETHI = item.MADETHI;
                mh.TENDETHI = item.TENDETHI;
                mh.SOCAUHOI = int.Parse(item.SOCAUHOI.ToString());
                mh.THOIGIAN = int.Parse(item.THOIGIAN.ToString());
                mh.NGAYTAODE = DateTime.Parse(item.NGAYTAODE.ToString());
                dsmh.Add(mh);
            }
            return dsmh;
        }
        public DeThiTbl ThongTinDeThi(string Madethi)
        {
            dt = GetKetnoi();
            DETHI dthi = dt.DETHIs.SingleOrDefault(i => i.MADETHI == Madethi);
            DeThiTbl dttbl = new DeThiTbl();
            dttbl.MADETHI = Madethi;
            dttbl.TENDETHI = dthi.TENDETHI;
            dttbl.THOIGIAN = int.Parse(dthi.THOIGIAN.ToString());
            dttbl.NGAYTAODE = DateTime.Parse(dthi.NGAYTAODE.ToString());
            dttbl.SOCAUHOI = int.Parse(dthi.SOCAUHOI.ToString());
            return dttbl;
        }
    }
}
